package com.zzzm.hospital.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zzzm.hospital.R;

import java.util.List;

public class DepartmentSystemAdapter extends RecyclerView.Adapter<DepartmentSystemAdapter.DepartmentSystemHolder> {

    private Context context;
    private List<String> departmentSystemList;
    private int currentSelectItem=0;

    public DepartmentSystemAdapter(Context context) {
        this.context = context;
    }

    public void setDepartmentSystemList(List<String> departmentSystemList) {
        this.departmentSystemList = departmentSystemList;
    }

    @NonNull
    @Override
    public DepartmentSystemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        DepartmentSystemHolder holder = new DepartmentSystemHolder(LayoutInflater.from(context).
                inflate(R.layout.department_system, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull DepartmentSystemAdapter.DepartmentSystemHolder holder, int position) {
        TextView departmentText = holder.departmentSystemText;
        View departmentView = holder.departmentSystemView;

        departmentText.setText(departmentSystemList.get(position));

        if (currentSelectItem == position) {
            holder.itemView.setBackgroundColor(departmentText.getResources().getColor(R.color.app_button_background,
                    null));

            departmentText.setTextColor(departmentText.getResources().getColor(R.color.two_left_item_btn));

            departmentView.setVisibility(View.VISIBLE);

            departmentView.setBackground(departmentView.getResources().getDrawable(R.drawable.appointment_item_view_shape, null));
        } else {
            departmentText.setBackgroundColor(departmentText.getResources().getColor(R.color.two_left_background,
                    null));
        }
    }

    @Override
    public int getItemCount() {
        return null == departmentSystemList ? 0 : departmentSystemList.size();
    }

    class DepartmentSystemHolder extends RecyclerView.ViewHolder {

        TextView departmentSystemText;
        View departmentSystemView;

        public DepartmentSystemHolder(@NonNull View itemView) {
            super(itemView);
            departmentSystemText = itemView.findViewById(R.id.department_system_text);
            departmentSystemView = itemView.findViewById(R.id.department_system_view);
        }
    }

}
